import { RendererStatus } from '@/core/renderer';
import { createSlice, PayloadAction } from '@reduxjs/toolkit';


export type CanvasSize = {
  width: number,
  height: number,
};

type InitialState = {
  rendererStaus: RendererStatus,
  mainDOMRect: CanvasSize
  rasterDOMRect: CanvasSize
}

const getDefaultDOMRect = (): CanvasSize => {
  return {
    width: 300,
    height: 200,
  }
}

const initialState: InitialState = {
  rendererStaus: 'pending',
  mainDOMRect: getDefaultDOMRect(),
  rasterDOMRect: getDefaultDOMRect(),
}

export default createSlice({
  name: 'canvas',
  initialState,
  reducers: {
    setMain: (state, action: PayloadAction<CanvasSize>) => {
      state.mainDOMRect = {
        ...state.mainDOMRect,
        ...action.payload
      }
    },
    setRaster: (state, action: PayloadAction<CanvasSize>) => {
      state.rasterDOMRect = {
        ...state.rasterDOMRect,
        ...action.payload
      }
    },
    setRendererStatus: (state, action: PayloadAction<RendererStatus>) => {
      state.rendererStaus = action.payload
    },
  },
});